home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
basic
/
integral.zip
/
TRAP.BAS
< prev
next >
Wrap
BASIC Source File
|
1994-03-22
|
3KB
|
70 lines
$If 0
╔═══════════════════════════════════════════════╤═══════════════╗
║ Program : Trapazoidal Area │ Version : 0.0 ║
╟────────────────────────────────┬──────────────┴───────────────╢
║ Written by Kurt J. Wolf │ [X] Released to public ║
║ Copyright 1994 by Kurt J. Wolf │ [ ] Do not release to public ║
╟────────────────────────────────┼──────────────────────────────╢
║ Compiler : PowerBASIC │ Compiler Version : 3.0c ║
╚════════════════════════════════╧══════════════════════════════╝
Home : 39 Brentwood Rd School : PSU - MA Box 267
Camp Hill, PA 17011 Mont Alto, PA 17237
(717) 763-8913 (717) 749-6430
InterNet : kjw124@psuvm.psu.edu
───────────────────────────────────────────────────────< Notes >─
---This is the PowerBASIC version of a program I have to do
for my engineering class. It uses the trapazoid rule to
evaluate an integral given the two end points and the number
of sub intervals.
** Error **
---For some odd reason, the change in the x value (DeltaX) is
0. This is an incorrect value. It should be 0.1.
Lloyd says to use # instead of &. We will try this.
** Fixed **
---Changing the & to # fixed the problem. This will be released
to public domain.
---Thank you very much Lloyd!
n - 1
{ -----------] }
| \ |
/\ | \ |
/ \ | f(a) + f(b) \ |
/----\ = DeltaX | ----------- + > f(xi) |
/ \ | 2.0 / |
/ \ | / |
| / |
{ -----------] }
i = 1
Where : DeltaX = change in x value
n = number of subintervals
a = lower limit
b = upper limit
$Endif
function f#(x#) public
f# = (x# ^ 2) + 1.0
end function
function integrand# (lower#, upper#, n#) public
deltax# = (upper#-lower#) / n#
for i# = 1 to n# - 1
x# = x# + deltax#
sum# = f#(x#) + sum#
next i#
sum# = ((f#(lower#) + f#(upper#)) / 2.0) + sum#
sum# = sum# * deltax#
integrand# = sum#
end function
print str$(integrand#(0, 1, 10))
print str$(integrand#(0, 1, 20))
print str$(integrand#(0, 1, 100))